class ManpagesZh < Formula
  desc "Chinese manual pages for Linux/Unix commands"
  homepage "https://github.com/man-pages-zh/manpages-zh"
  url "https://github.com/man-pages-zh/manpages-zh/archive/refs/heads/master.tar.gz"
  sha256 "5c4c4caadeee341865d8a846dea70c4733aa2b76d21991ab4c26276b162bdcc0"
  version "1.0"
  license "GPL-3.0"

  depends_on "cmake" => :build
  depends_on "python" => :build
  depends_on "opencc" => :build
  depends_on "groff" => :recommended

  def install
    args = std_cmake_args + %W[
      -DENABLE_ZHCN=ON
      -DENABLE_ZHTW=OFF
      -DENABLE_APPEND_COLOPHON=ON
    ]

    mkdir "build" do
      system "cmake", "..", *args
      system "make", "-j#{ENV.make_jobs}"
      system "make", "install"
    end

    (bin/"cman").write <<~EOS
      #!/bin/sh
      man -M "#{share}/man/zh_CN" "$@"
    EOS
    chmod 0755, bin/"cman"
  end

  def post_install
    ohai "中文手册路径已安装到：#{share}/man/zh_CN"
    puts "使用示例：cman ls"
  end

  test do
    assert_match "用法", shell_output("MANPATH=#{share}/man/zh_CN man ls 2>&1", 1)
  end
end